class Solution {
public:
    vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {
        multiset<int> st1(nums1.begin(),nums1.end());
        multiset<int> st2(nums2.begin(),nums2.end());
                vector<int> v;
        auto it1 = st1.begin();
        auto it2 = st2.begin();
        while (it1 != st1.end() && it2 != st2.end())
        {
            if (*it1 < *it2)
            {
                ++it1;
            }
            else if (*it1 > *it2)
            {
                ++it2;
            }
            else
            {
                v.push_back(*it1);
                ++it1; ++it2;
            }

        }
    return v;
    }
};
